#pragma once
#include <stdint.h>
#include <stdbool.h>

struct Buffer
{
    //指向内存的指针
    char *data;
    int32_t capacity;
    int32_t readPos;
    int32_t writePos;
};

//初始化
struct Buffer *bufferInit(int32_t size);
void bufferDestroy(struct Buffer *buffer);

//扩容
void bufferExtendRoom(struct Buffer *buffer, int32_t size);
//得到剩余的可写的内存容量
int32_t bufferWriteableSize(struct Buffer *buffer);
//得到剩余的可读的内存容量
int32_t bufferReadableSize(struct Buffer *buffer);
//写内存 1.直接写 2.接收套接字数据
int8_t bufferAppendData(struct Buffer *buffer, const char *data, int32_t size);
int8_t bufferAppendString(struct Buffer *buffer, const char *data);
int32_t bufferSocketRead(struct Buffer *buffer, int32_t fd);
//根据\r\n取出一行，找到其在数据块中的位置，返回该位置
char *bufferFindCRLF(struct Buffer *buffer);
int32_t bufferSendData(struct Buffer *buffer, int32_t socket);